const Koa = require('koa')
const views = require("koa-views")
const {resolve} = require('path')
const {initSchemas, connect} = require("./database/init")
const R = require('ramda')
const MIDDLEWARES = ['route', 'parcel']




const useMiddlewares = app => {
    R.map(
        R.compose(
            R.forEachObjIndexed(
                initWith => initWith(app)
            ),
            require,
            name => resolve(__dirname, `./middlewares/${name}`)
        )
    )(MIDDLEWARES)
}



;(async ()=>{
    await connect()
    initSchemas()
    // require("./tasks/movie")
    // require("./tasks/api")
    // require("./crawler/video.js")

    const app = new Koa()
    await useMiddlewares(app)
    app.listen(2018)
})()



/*
    ctx.body = pug.render(pugTpl, {
        you: 'Jack',
        me: 'Movie'
    })
*/ 


// app.use(views(resolve(__dirname, './views'),{
//     extension: 'pug'
// }))

// app.use(async (ctx, next) => {
//     ctx.type = 'text/html;charset=utf-8'
//     await ctx.render('index', {
//         you: 'lucy',
//         me: 'imooc'
//     })
// })
// app.use(router.routes())
//  .use(router.allowedMethods())